// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: linchuan

#pragma once

#include <memory>
#include <string>

#include "coin2/exchange/base/order/order.h"

#include "coin2/exchange/okex_common/api_util/auth_key.h"
#include "coin2/exchange/order/okex.pb.h"

class OkexNativePrivateClient : public coin2::exchange::base::order::NativePrivateClient {
 public:
  using RestParams = coin2::exchange::order::OkexRestParams;
  using NativeClientConfig = coin2::exchange::order::OrderConnectionConfig;

 public:
  std::shared_ptr<AsioHttpContext> SubmitOrderExecution(const OrderExecutionProto& order);
  std::shared_ptr<AsioHttpContext> SubmitRestQuery(const RestQueryProto& query);

 public:
  explicit OkexNativePrivateClient(const NativeClientConfig& config);

  std::shared_ptr<AsioHttpContext> QueryAccountInfo();
  std::shared_ptr<AsioHttpContext> QueryOrders(const std::string& instrument_id, int state);
  std::shared_ptr<AsioHttpContext> QueryFills(const std::string& instrument_id, int limit);
  std::shared_ptr<AsioHttpContext> PlaceOrder(const RestParams& params);
  std::shared_ptr<AsioHttpContext> AmendOrder(const RestParams& params);
  std::shared_ptr<AsioHttpContext> CancelSingleOrder(const RestParams& params);
  std::shared_ptr<AsioHttpContext> CancelOrders(const RestParams& params);

  std::shared_ptr<AsioHttpContext> PlaceOrderNorm(const OrderExecution&) override;
  std::shared_ptr<AsioHttpContext> AmendOrderNorm(const OrderExecution&) override;
  std::shared_ptr<AsioHttpContext> CancelOrderNorm(const OrderExecution&) override;

  RestParams GetRestOrderParams(const OrderSpec& order_spec, int64_t proc_order_id);
  RestParams GetRestAmendParams(
      const OrderSpec& order_spec,
      const std::string& exchange_order_id,
      int64_t proc_order_id,
      int64_t orig_proc_order_id);
  RestParams GetRestCancelParams(const IOrderContext& order_context);

  std::shared_ptr<AsioHttpContext> QueryTransfer(const std::string& ccy, const std::string& type);
};
